package cn.dliyy.warehouse.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.dliyy.warehouse.bean.BBrand;
import cn.dliyy.warehouse.bean.BDealer;
import cn.dliyy.warehouse.service.BBrandService;

@Controller
@RequestMapping(value = "/brand")
public class BBrandController {

	@Resource
	private BBrandService bBrandService;
	@Resource
	private BBrand bBrand;

	@RequestMapping(value ={"", "/"})
	public String load(ModelMap modelMap) {
		List<?> list = bBrandService.getList(BBrand.class);
		modelMap.put("list", list);
		return "/base/brand";
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String create(ModelMap modelMap) {
		modelMap.addAttribute("brand",bBrand);
		return "/base/brand_add";
	}

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public String create(@Valid @ModelAttribute("brand") BBrand bBrand, BindingResult result, ModelMap mp) {
		bBrandService.save(bBrand);
		return "redirect:/brand/";
	}

}
